﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using UniMana.Win.Systems;
using UniMana.Data;
using System.Configuration;
using System.Diagnostics;

namespace UniMana.Win
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            DevExpress.Utils.AppearanceObject.DefaultFont = new System.Drawing.Font(ConfigurationManager.AppSettings["FontName"], float.Parse(ConfigurationManager.AppSettings["FontSize"]));
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new a_FrmLogin());
            if (SysGlobalVar.u_sta_CheckLogin == true)
            {
                string strUserName = SysGlobalVar.g_sta_sysUserLogin.Properties.UserName;
                string strPermission = "FrmMain";

                var role = System_RuleData.CheckRoleByUsername(new DBMain(), strUserName, strPermission);
                IQueryable<System_Group> group = System_GroupData.GetGroupByUserKey(new DBMain(), SysGlobalVar.g_sta_sysUserLogin.Properties.System_UserKey);

                OpenFrmByGroup(group);
               
            }
        }

        private static bool KillProcByName(string strProcname)
        {
            bool Result = false;
            string strTemp = strProcname.ToLower().Trim().Replace(".exe", string.Empty);
            foreach (Process process in Process.GetProcesses())
            {
                if (process.ProcessName.ToLower() == strTemp)
                {
                    process.Kill();
                    Result = true;
                    break;
                }
            }
            return Result;
        }

        public static void OpenFrmByGroup(IQueryable<System_Group> sys_Group)
        {
            if (sys_Group.Count() > 1)
            {
                //FrmMainMindMap f = 
                Application.Run(new FrmMain());
                //f.ShowDialog();
            }
            else
            {
                Application.Run(new FrmMain());
                //if (sys_Group.Count() == 1)
                //{
                //    System_Group sg = sys_Group.FirstOrDefault();
                //    switch (sg.System_GroupKey)
                //    {
                //        case 1: Application.Run(new FrmTrainingManager()); break;
                //        case 2: Application.Run(new FrmTrainingManager());/*MessageBox.Show("Hệ thống đang phát triển");*/ break;
                //        case 3: MessageBox.Show("Hệ thống đang phát triển"); break;
                //        case 4: MessageBox.Show("Hệ thống đang phát triển"); break;
                //        case 5: MessageBox.Show("Hệ thống đang phát triển"); break;
                //        default: Application.Run(new FrmTrainingManager()); break;
                //    }
                //}
            }
        }
    }
}
